home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-05-09 | 2.5 KB | 109 lines | [TEXT/PICN] |
- ############################################################################
- #
- # deal.icn
- #
- # This program shuffles, deals, and displays hands in the game
- # of bridge. An example of the output of deal is
- # ---------------------------------
- #
- # S: KQ987
- # H: 52
- # D: T94
- # C: T82
- #
- # S: 3 S: JT4
- # H: T7 H: J9863
- # D: AKQ762 D: J85
- # C: QJ94 C: K7
- #
- # S: A652
- # H: AKQ4
- # D: 3
- # C: A653
- #
- # ---------------------------------
- #
- # Options: The following parameter string options are available:
- #
- # -h n Produce n hands. The default is 4.
- #
- # -s n Set the seed for random generation to n. Different
- # seeds give different hands. The default seed is 0.
- #
- ############################################################################
- #
- # Links: getopt, shuffle
- #
- ############################################################################
-
- link getopt, shuffle
-
- global deck, deckimage, handsize, suitsize, denom, rank, blanker
-
- procedure main(args)
- local hands, opts
-
- deck := deckimage := &lcase || &ucase # initialize global variables
- handsize := suitsize := *deck / 4
- rank := "AKQJT98765432"
- blanker := repl(" ",suitsize)
- denom := &lcase[1+:suitsize]
-
- opts := getopt(args,"h+s+")[1]
- hands := \opts["h"] | 4
- &random := \opts["s"]
-
- every 1 to hands do
- display()
-
- end
-
- # Display the hands
- #
- procedure display()
- local layout, i
- static bar, offset
-
- initial {
- bar := "\n" || repl("-",33)
- offset := repl(" ",10)
- }
-
- deck := shuffle(deck)
- layout := []
- every push(layout,show(deck[(0 to 3) * handsize + 1 +: handsize]))
-
- write()
- every write(offset,!layout[1])
- write()
- every i := 1 to 4 do
- write(left(layout[4][i],20),layout[2][i])
- write()
- every write(offset,!layout[3])
- write(bar)
- end
-
- # Put the hands in a form to display
- #
- procedure show(hand)
- static clubmap, diamondmap, heartmap, spademap
- initial {
- clubmap := denom || repl(blanker,3)
- diamondmap := blanker || denom || repl(blanker,2)
- heartmap := repl(blanker,2) || denom || blanker
- spademap := repl(blanker,3) || denom
- }
- return [
- "S: " || arrange(hand,spademap),
- "H: " || arrange(hand,heartmap),
- "D: " || arrange(hand,diamondmap),
- "C: " || arrange(hand,clubmap)
- ]
- end
-
- # Arrange hands for presentation
- #
- procedure arrange(hand,suit)
- return map(map(hand,deckimage,suit) -- ' ',denom,rank)
- end
-